#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2.6e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int dfn[N], cnt;
int dep[N], fa[N][18], mn[N][18];
void dfs(int u, int fu, int w) {
  dfn[u] = ++cnt;
  dep[u] = dep[fu] + 1;
  fa[u][0] = fu;
  mn[u][0] = w;
  rep(i, 1, 17) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  rep(i, 1, 17) mn[u][i] = min(mn[u][i - 1], mn[fa[u][i - 1]][i - 1]);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u, W[i]);
  }
  head[u] = 0;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(i, 17, 0) if (d & (1 << i)) u = fa[u][i];
  if (u == v) return u;
  per(i, 17, 0) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
ll query(int u, int d) {
  int ans = 1e9;
  per(i, 17, 0) if (d & (1 << i)) ans = min(ans, mn[u][i]), u = fa[u][i];
  return ans;
}
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
int k, a[N];
int st[N], top;
int sz[N];
void build() {
  sort(a + 1, a + k + 1, cmp);
  rep(i, 1, k) sz[a[i]] = 1;
  st[top = 1] = 1;
  if (a[1] != 1) st[++top] = a[1];
  rep(i, 2, k) {
    int x = lca(st[top], a[i]);
    while (top > 1 && dep[st[top - 1]] >= dep[x])
      add(st[top - 1], st[top]), top--;
    if (x != st[top]) add(x, st[top]), st[top] = x;
    st[++top] = a[i];
  }
  while (top > 1) add(st[top - 1], st[top]), top--;
}
ll dp[N];
void dfs2(int u) {
  ll sum = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    dfs2(v);
    ll now = sz[v] ? 1e18 : dp[v];
    sz[v] = 0;
    sum += min(now, query(v, dep[v] - dep[u]));
  }
  dp[u] = sum;
  head[u] = 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  dfs(1, 0, 0);
  cin >> m;
  while (m--) {
    cin >> k;
    rep(i, 1, k) cin >> a[i];
    tot = 0;
    build();
    dfs2(1);
    sz[1] = 0;
    cout << dp[1] << endl;
  }
  return 0;
}